package org.msfj.hospital.service.impl;

import org.msfj.hospital.model.HospitalEvaluate;
import org.msfj.hospital.vo.HospitalEvaluateVo;
import org.msfj.hospital.service.HospitalEvaluateService;
import org.msfj.common.base.BaseServiceImpl;
import org.msfj.common.annotation.Constants;
import org.msfj.common.enums.Enable;
import org.springframework.stereotype.Service;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.beans.BeanUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import cn.hutool.core.collection.CollectionUtil;
import tk.mybatis.mapper.entity.Example;
import java.util.List;
import java.util.ArrayList;

/**
 * @Description: 医院评价信息service实现类
 * @Author: like
 * @Email: like@deyatong.com
 * @Date: 2018-08-21 14:17:50
 * @Version: 1.0
 * @Created in idea by autoCode
 */
@Service
@CacheConfig(cacheNames = Constants.CACHE_NAMESPACE + "hospitalEvaluate")
public class  HospitalEvaluateServiceImpl extends BaseServiceImpl<HospitalEvaluate> implements HospitalEvaluateService {

    /**
     * 根据条件分页查询医院评价信息列表
     *
     * @param hospitalEvaluateVo
     * @param page 当前第几页
     * @param rows 每页多少条记录
     * @return PageInfo<HospitalEvaluate>
     */
    @Override
    //@Cacheable
    public PageInfo<HospitalEvaluateVo> getByHospitalEvaluate(HospitalEvaluateVo hospitalEvaluateVo, int page, int rows) {
        Example example = new Example(HospitalEvaluate.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("enable", Enable.ENABLE.getCode());
        PageHelper.startPage(page, rows);
        List<HospitalEvaluate> hospitalEvaluateList = super.getByExample(example);
        PageInfo hospitalEvaluateVoPageInfo = new PageInfo(hospitalEvaluateList);
        hospitalEvaluateVoPageInfo.setList(setOtherProperties(hospitalEvaluateList));
        return hospitalEvaluateVoPageInfo;
    }

    /**
     * 根据条件查询所有医院评价信息对象列表
     *
     * @param hospitalEvaluateVo
     * @return List<HospitalEvaluate>
     */
    @Override
    //@Cacheable
    public List<HospitalEvaluateVo> getAllHospitalEvaluate(HospitalEvaluateVo hospitalEvaluateVo) {
        Example example = new Example(HospitalEvaluate.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("enable", Enable.ENABLE.getCode());
        List<HospitalEvaluateVo> hospitalEvaluateVoList = setOtherProperties(super.getByExample(example));
        return hospitalEvaluateVoList;
    }

    /**
     * 设置vo的其他属性属性
     *
     * @param hospitalEvaluate
     * @return DepartmentVo
     */
    @Override
    //@Cacheable
    public HospitalEvaluateVo setOtherProperties(HospitalEvaluate hospitalEvaluate) {
        HospitalEvaluateVo hospitalEvaluateVo = new HospitalEvaluateVo();
        BeanUtils.copyProperties(hospitalEvaluate, hospitalEvaluateVo);
        return hospitalEvaluateVo;
    }

    /**
     * 设置vo的其他属性属性
     *
     * @param hospitalEvaluates
     * @return List<HospitalEvaluateVo>
    */
    @Override
    //@Cacheable
    public List<HospitalEvaluateVo> setOtherProperties(List<HospitalEvaluate> hospitalEvaluates) {
        List<HospitalEvaluateVo> hospitalEvaluateVos = new ArrayList<>();
        if (CollectionUtil.isNotEmpty(hospitalEvaluates)) {
            for (HospitalEvaluate hospitalEvaluate : hospitalEvaluates) {
                HospitalEvaluateVo hospitalEvaluateVo = new HospitalEvaluateVo();
                BeanUtils.copyProperties(hospitalEvaluate, hospitalEvaluateVo);
                hospitalEvaluateVos.add(hospitalEvaluateVo);
            }
        }
        return hospitalEvaluateVos;
    }
}
